<template>
  <div>
    <button v-on:click="add">Add</button>
    <button v-on:click="remove">Remove</button>
    <button v-on:click="shuffle">shuffle</button>
    <transition-group tag="ul" name="list" appear>
      <li v-for="(item, i) in list" :key="item" class="li_item">
        {{ item }}
        <span @click="del(i)">del</span>
      </li>
    </transition-group>
  </div>
</template>

<script>
import { shuffleList } from "@/utils";
export default {
  data() {
    return { list: [1, 2, 3, 4, 5, 6, 7], num: 10 };
  },
  created() {},
  methods: {
    shuffle() {
      this.list = shuffleList(this.list);
    },
    add() {
      this.list.splice(this.randomNum(), 0, this.num++);
    },
    remove() {
      this.list.splice(this.randomNum(), 1);
    },
    randomNum() {
      return Math.floor(Math.random() * this.list.length);
    },
    del(i) {
      this.list.splice(i, 1);
    }
  }
};
</script>

<style scoped>
.list-enter,
.list-leave-to {
  transform: translateY(10px);
}

/* .list-enter-active, */
.list-leave-active {
  position: absolute;
  /* transition: all 0.3s ease-in; */
}

.list-move {
  transition: transform 1s;
}

li {
  width: 200px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

li:nth-child(even) {
  background-color: #eee;
}

span {
  font-size: 10px;
  color: #ccc;
  user-select: none;
  cursor: pointer;
}

.li_item {
  margin-bottom: 10px;
  transition: transform 0.3s ease-in;
}
</style>
